package com.shudu.library.view.textview;

import android.annotation.TargetApi;
import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;

/**
 * Created by Wind_Fantasy on 15/7/22.
 */
public class AutoFouceMarqueeTextView extends AppCompatTextView{
    public AutoFouceMarqueeTextView(Context context) {
        super(context);
        init();
    }

    public AutoFouceMarqueeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public AutoFouceMarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }


    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        super.onWindowFocusChanged(hasWindowFocus);
        if(!hasWindowFocus){
            setSelected(true);
        }
    }

    @Override
    public boolean isFocused() {
        return true;
    }

    private void init(){
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        setMarqueeRepeatLimit(-1);
        setSingleLine(true);
        setSelected(true);
    }

}
